package testIntergration;


import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import FamilyTherapy.Game;
import FamilyTherapy.GCWindow;

public class testGCWindow_reqestNoOfPlayer {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testRequestNoOfPlayer_1() {
		int result;

		Game game = new Game();
		GCWindow gwindow = new GCWindow();

		//for output
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));
				
		String expected = "Number of player (2-6): ";
		
		//for input
		String data = "2"; 	//data to be input 
		InputStream stdin = System.in; 
		try {   
			System.setIn(new ByteArrayInputStream(data.getBytes()));	//put data to input stream
			result = gwindow.requestNoOfPlayer(game);	//for getting data from input stream
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		
		//for testing
		assertEquals(expected,outContent.toString());
		assertEquals(result, 2);
	}
	
	@Test
	public void testRequestNoOfPlayer_2() {
		int result;

		Game game = new Game();
		GCWindow gwindow = new GCWindow();

		//for output
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));	
		
		String expected = "Number of player (2-6): "+
		"Please input a number between 2 and 6.\n"+
		"Number of player (2-6): ";
		
		//for input
		String data = "7 2"; 	//data to be input 
		InputStream stdin = System.in; 
		try {   
			System.setIn(new ByteArrayInputStream(data.getBytes()));	//put data to input stream
			result = gwindow.requestNoOfPlayer(game);	//for getting data from input stream
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		
		//for testing
		assertEquals(expected,outContent.toString());
		assertEquals(result, 2);
	}
	@Test
	public void testRequestNoOfPlayer_3() {
		int result;

		Game game = new Game();
		GCWindow gwindow = new GCWindow();

		//for output
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));	
		
		String expected = "Number of player (2-6): "+
		"Please input a number between 2 and 6.\n"+
		"Number of player (2-6): "+
		"Please input a number between 2 and 6.\n"+
		"Number of player (2-6): ";
		
		//for input
		String data = "7 7 2"; 	//data to be input 
		InputStream stdin = System.in; 
		try {   
			System.setIn(new ByteArrayInputStream(data.getBytes()));	//put data to input stream
			result = gwindow.requestNoOfPlayer(game);	//for getting data from input stream
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		
		//for testing
		assertEquals(expected,outContent.toString());
		assertEquals(result, 2);
	}
	@Test
	public void testRequestNoOfPlayer_4() {
		int result;

		Game game = new Game();
		GCWindow gwindow = new GCWindow();

		//for output
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));	
		
		String expected = "Number of player (2-6): "+
		"Please input a number between 2 and 6.\n" +
		"Please input an integer.\n" +
		"Please input an integer.\n"+
		"Number of player (2-6): ";
		
		//for input
		String data = "8 a + 2"; 	//data to be input 
		InputStream stdin = System.in; 
		try {   
			System.setIn(new ByteArrayInputStream(data.getBytes()));	//put data to input stream
			result = gwindow.requestNoOfPlayer(game);	//for getting data from input stream
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		
		//for testing
		assertEquals(expected,outContent.toString());
		assertEquals(result, 2);
	}
}
